<template>
	<view class="container">
		<!-- 用户信息区 -->
		<view class="user-info">
			<view class="avatar-wrap">
				<image class="avatar" :src="userinfo.avatar || '/static/logo.png'" mode="aspectFill" />
			</view>
			<view class="info-content">
				<text class="username">{{userinfo.nickname?userinfo.nickname:'微信用户'}}</text>
				<text @click="cptj" :data-id="userinfo.tuijian" class="balance">邀请码： <text > {{userinfo.tuijian}}
					</text></text>
			</view>
		</view>
		
		<view class="orderbox">
			
			<view class="orderli">
				<view class="orderlit">{{orderinfo.count}} </view>
				<view class="orderlib">累计订单</view>
			</view>
			<view class="orderli">
				<view class="orderlit"> {{orderinfo.money}} </view>
				<view class="orderlib">订单金额</view>
			</view>
			<view class="orderli">
				<view class="orderlit"> {{orderinfo.getmoney}} </view>
				<view class="orderlib">订单收益</view>
			</view>
			
		</view>
		
		
		<!-- 功能区 -->
		<view class="section">
			<view class="section-title">常用功能</view>
			<view class="menu-list">
			

				<view class="menu-item" @click="nexturl" data-url="/pages/order/index">
					<view  class="menu-item-content">
						<uni-icons type="list" size="20" color="#666" />
						<text class="menu-text"> 订单管理 </text>
					</view>
					<uni-icons type="right" size="16" color="#999" />
				</view>
				
				<view class="menu-item" @click="nexturl" data-url="/pages/data/index">
					<view  class="menu-item-content">
						<uni-icons type="paperclip" size="20" color="#666" />
						<text class="menu-text"> 服务订单 </text>
					</view>
					<uni-icons type="right" size="16" color="#999" />
				</view>
				
				<view class="menu-item" @click="nexturl" data-url="/pages/user/set">
					<view class="menu-item-content" >
						<uni-icons type="gear" size="20" color="#666" />
						<text class="menu-text"> 个人信息 </text>
					</view>
					<uni-icons type="right" size="16" color="#999" />
				</view>
				

			</view>
		</view>

		<!-- 退出登录 -->
		<view class="logout-section">
			<button class="logout-btn" type="warn" @click="handleLogout">退出登录</button>
		</view>

		<view style="height: 100px;"></view>

	</view>


</template>

<script>
	import {
		curl
	} from 'common/api.js';
	export default {
		data() {
			return {
				userinfo: [],
				orderinfo:[]
			}
		},
		onShow() {
			var that = this;

			curl('user/index', {}).then((res) => {
				console.log(res)
				that.userinfo = res.data
			})
			
			this.getorderinfo();
		},
		methods: {
			//订单统计
			
			getorderinfo(){
				var that = this;
				
				curl('merch/getorderinfo', {}).then((res) => {
					console.log(res)
					that.orderinfo = res.data
				})
				
			},
			
			//退出登录
			handleLogout(){
				uni.setStorageSync('token','');
				uni.reLaunch({
					url:"/pages/login/login"
				})
			},
			
			// 页面跳转
			nexturl(ret) {
				uni.navigateTo({
					url: ret.currentTarget.dataset.url
				})
			},

			//复制内容
			cptj(ret) {
				var id = ret.currentTarget.dataset.id;
				uni.setClipboardData({
					data: id,
					success: function() {
						uni.showToast({
							title: '复制成功',
							icon: 'none'
						})
					}
				})
			},

		}
	}
</script>

<style>
	
	.orderli{
		width: 200rpx;
		height: 140rpx;
		text-align: center;
	}
	
	.orderlit{
		font-weight: bold;
		font-size: 38rpx;
		color: red;
		height: 70rpx;
		line-height: 100rpx;
	}
	.orderlib{
		font-weight: 400;
		font-size: 26rpx;
		color: #555555;
		height: 70rpx;
		line-height: 70rpx;
	}
	.orderbox{
		width: 690rpx;
		height: 200rpx;
		margin:20rpx auto;
		background: #ffffff;
		border-radius: 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;
	}
	
	page {
		height: 100%;
		background-color: #f5f5f5;
	}

	.container {
		min-height: 100%;
		padding: 0 30rpx;
	}

	.user-info {
		display: flex;
		align-items: center;
		padding: 40rpx 30rpx;
		margin: 30rpx 0;
		background-color: #ffffff;
		border-radius: 16rpx;
		box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
	}

	.avatar-wrap {
		flex-shrink: 0;
		width: 120rpx;
		height: 120rpx;
		margin-right: 30rpx;
		border-radius: 60rpx;
		overflow: hidden;
	}

	.avatar {
		width: 100%;
		height: 100%;
	}

	.info-content {
		flex: 1;
	}

	.username {
		display: block;
		font-size: 18px;
		font-weight: 500;
		color: #333333;
		margin-bottom: 8rpx;
	}

	.balance {
		font-size: 14px;
		color: #FF6B6B;
		font-weight: 500;
	}

	.section {
		margin-bottom: 30rpx;
		background-color: #ffffff;
		border-radius: 16rpx;
		padding: 20rpx 0;
	}

	.section-title {
		padding: 20rpx 30rpx;
		font-size: 16px;
		color: #333333;
		font-weight: 500;
	}

	.menu-list {
		padding: 0 30rpx;
	}

	.menu-item {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx 0;
		border-bottom: 1px solid #f5f5f5;
	}

	.menu-item:last-child {
		border-bottom: none;
	}

	.menu-item-content {
		display: flex;
		align-items: center;
	}

	.menu-text {
		margin-left: 20rpx;
		font-size: 15px;
		color: #333333;
	}

	.logout-section {
		padding: 60rpx 30rpx;
	}

	.logout-btn {
		width: 100%;
		height: 88rpx;
		line-height: 88rpx;
		text-align: center;
		border-radius: 44rpx;
		font-size: 16px;
	}
</style>